package sh.util;

import org.apache.struts2.ServletActionContext;
import sh.model.User;
import sh.orm.util.HttpConst;

import javax.servlet.http.HttpSession;

/**
 * @author lqq
 * @date 2019/1/18
 */
public abstract class SessionUtil {
    public static Long getCurrentUserId(){
        HttpSession session = ServletActionContext.getRequest().getSession();
        User user = (User)session.getAttribute(HttpConst.SESSION_CURRENT_USER);
        if(user == null){
            throw new RuntimeException("当前用户未登录");
        }
        return user.getId();
    }

    public static HttpSession getSession() {
        return  ServletActionContext.getRequest().getSession();
    }
}
